<script>
$(function() {
	$( "#tabs" ).tabs({
	    select: function(event, ui) {
	        var url = $.data(ui.tab, 'load.tabs');
	        if( url ) {
	            location.href = url;
	            return false;
	        }
	        return true;
	    },
	selected: 1 
	});
});
</script>
<div id="tabs">
	<ul>
    <li><?php echo $this->Html->link(__('Danh sách quyền', true), array('controller'=>'roles','action' => 'index')); ?></li>
    <li><a href='#accordion'>Danh sách chức vụ</a> </li>
    <li><?php echo $this->Html->link(__('Danh sách chi đoàn', true), array('controller'=>'phanquyens','action' => 'phanquyencd')); ?></li>
	</ul>
<div id='accordion' class="index">
<h3><a href="#">Danh sách chức vụ</a></h3>
<div>
<?php echo $form->create('Phanquyen');?>
<table>
<tr>
<td><?php echo $form->input('loaidv',array('id'=>'loaidv','label'=>'Loại user','type'=>'select','options'=>array(0=>'Sinh viên',1=>'Cán bộ'),'selected'=>0));?></td>
<td><?php echo $form->input('chucvu',array('id'=>'chucvu','label'=>'Chức danh','type'=>'select','options'=>$chucvus,'empty'=>'-- Chọn chức danh --'));?></td>
</tr>
</table>
<div id='div_ds'>
<table id='tables'>
<tr>
<th>STT</th>
<th>Họ tên</th>
<th>Chi đoàn</th>
<?php foreach ($quyens as $quyen_id=>$quyenval):?>
<th><?php echo $quyenval;?></th>
<?php endforeach;?>
</tr>
</table>
</div>
</div>
<?php $this->Js->get('#loaidv')->event('change',
							$this->Js->request(array('controller' => 'phanquyens', 'action' => 'updatedspqchucdanh'),
							array('update' => '#div_ds','async' => true,
							'dataExpression' => true,'method' => 'post',
							'data' => $js->serializeForm(array('isForm' => false, 'inline' => true)))));?>
<?php $this->Js->get('#chucvu')->event('change',
							$this->Js->request(array('controller' => 'phanquyens', 'action' => 'updatedspqchucdanh'),
							array('update' => '#div_ds','async' => true,
							'dataExpression' => true,'method' => 'post',
							'data' => $js->serializeForm(array('isForm' => false, 'inline' => true)))));?>
<?php echo $form->end();?>
<h3><a href="#">Thêm - Xóa quyền</a></h3>
<?php echo $form->create('Phanquyen');?>
<div>
<table>
<tr>
<td><?php echo $form->input('loaidvadd',array('id'=>'loaidvadd','label'=>'Loại chi đoàn','type'=>'select','options'=>array(0=>'Sinh viên',1=>'Cán bộ'),'selected'=>0));?></td>
<td><?php echo $form->input('action',array('id'=>'action','label'=>'Thao tác','type'=>'select','options'=>array(0=>'Thêm',1=>'Xóa'),'selected'=>0));?></td>
</tr>
</table>
<table id='tables'>
<tr>
<th></th>
<?php foreach ($quyens as $quyen_id=>$quyenval):?>
<th><?php echo $quyenval.$form->input('checkall',array('class'=>'checkall','id'=>$quyen_id,'label'=>false,'type'=>'checkbox'));?></th>
<?php endforeach;?>
</tr>
<?php foreach ($chucvus as $chucvu_id=>$chucvu_val):?>
<tr>
<td><?php echo $chucvu_val;?></td>
<?php foreach ($quyens as $quyen_id=>$quyenval):?>
<td><?php echo $form->input('',array('name'=>'data[Phanquyen][checkbox]['.$chucvu_id.']['.$quyen_id.']','class'=>'check_'.$quyen_id,'label'=>false,'type'=>'checkbox'));;?></td>
<?php endforeach;?>
</tr>
<?php endforeach;?>
</table>
</div>
<?php echo $form->end(' Lưu ');?>
</div>
<script>
function validate()
{
	checknum =0;
	$("input:checkbox").each(function()
	{
			if($(this).prop('class')=='checkadd' && $(this).prop('checked')==true)
			{
				checknum +=1;
			}
	});
	if(checknum==0)
		return false;
	return true;
		
}
$(function(){
	$( "#accordion" ).accordion();
	$('.checkall').live('click',function(){
											id = $(this).prop('id');
											if($(this).prop('checked')==true)
												$('.check_'+id).prop('checked',true);
											else
												$('.check_'+id).prop('checked',false);
											});
});
</script>
</div>